﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MainTemplate.Master" AutoEventWireup="true" CodeBehind="HonorPicture.aspx.cs" Inherits="Enterprise.Admin.HonorPicture" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="../Content/Widget/fancyBox/jquery.fancybox.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/fancyBox/jquery.mousewheel.pack.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/fancyBox/jquery.easing.pack.js" type="text/javascript" charset="utf-8"></script>
    <link href="../Content/Widget/fancyBox/jquery.fancybox.css" rel="stylesheet" charset="utf-8"/>
    <script src="../Content/Widget/AjaxFileUploader/ajaxfileupload.js" type="text/javascript" charset="utf-8"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="table_list"></table>
    <div id="search_honor">
        <form id="search_honor_form" action="Handle/GetHonorPictureListJson.aspx" method="get">
            <p>
                <label>名称：</label><input type="text" name="CoName" />
            </p>
        </form>
    </div>
    <div id="add_honor">
        <form id="add_honor_form" action="Handle/AddHonor.aspx" method="post">
            <p>
                <label>名称：</label><input type="text" name="CoName" value="" />
                <input id="add_big_image" name="CoBigImage" type="hidden" value="" />
                <input id="add_normal_image" name="CoNormalImage" type="hidden" value="" />
                <input id="add_small_image" name="CoSmallImage" type="hidden" value="" />
            </p>
            <p class="en-us">
                <label>名称(En)：</label><input type="text" name="CoNameEn" value="" />
            </p>
            <p>
                <label>排序：</label><input type="text" name="CoSort" value="" />
            </p>
            <p>
                <label>图片：</label><span id="add_upload_box"><input type="file" id="add_upload" name="Filedata" /><input type="button" id="add_btn_upload" value="上传" /></span><span id="add_delete_box" style="display: none;"><a id="btn_add_delete_image" href="javascript:void(0);">重新上传【删除】</a></span>
            </p>
            <p>
                <label style="height: 130px;line-height: 130px;">描述：</label><textarea rows="5" cols="30" name="CoDescription"></textarea>
            </p>
            <p class="en-us">
                <label style="height: 130px;line-height: 130px;">描述(En)：</label><textarea rows="5" cols="30" name="CoDescriptionEn"></textarea>
            </p>
        </form>
    </div>
    <div id="edit_honor">
        <form id="edit_honor_form" action="Handle/EditHonor.aspx" method="post">
            <p>
                <label>名称：</label><input type="text" name="CoName" value="" />
                <input id="edit_honor_id" name="CoHonorId" type="hidden" value="" />
                <input id="edit_big_image" name="CoBigImage" type="hidden" value="" />
                <input id="edit_normal_image" name="CoNormalImage" type="hidden" value="" />
                <input id="edit_small_image" name="CoSmallImage" type="hidden" value="" />
            </p>
            <p>
                <label>名称(En)：</label><input type="text" name="CoNameEn" value="" />
            </p>
               <p>
                <label>排序：</label><input type="text" name="CoSort" value="" />
            </p>
            <p>
                <label>图片：</label><span id="edit_upload_box" style="display: none;"><input type="file" id="edit_upload" name="Filedata" /><input type="button" id="edit_btn_upload" value="上传" /></span><span id="edit_delete_box"><a id="btn_edit_delete_image" href="javascript:void(0);">重新上传【删除】</a></span>
            </p>
            <p>
                <label style="height: 130px;line-height: 130px;">描述：</label><textarea rows="5" cols="30" name="CoDescription" id="edit_honor_content"></textarea>
            </p>
            <p>
                <label style="height: 130px;line-height: 130px;">描述(En)：</label><textarea rows="5" cols="30" name="CoDescriptionEn"></textarea>
            </p>
        </form>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            var tableList = $("#table_list").datagrid({
                title: '企业荣誉列表',
                fit: true,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                url: 'Handle/GetHonorPictureListJson.aspx',
                idField: 'id',
                singleSelect: true,
                fitColumns: true,
                onClickRow: function (rowIndex) {
                    $('#table_list').datagrid("unselectRow", rowIndex);
                },
                onLoadSuccess: function () {
                    $(".fancybox_image").fancybox({
                        'transitionIn': 'none',
                        'transitionOut': 'none',
                        'titlePosition': 'over'
                    });
                },
                columns: [[
                         { title: 'Id', field: 'id', width: 280, align: 'center', checkbox: true },
                         { title: '名称', field: 'CoName', width: 280, align: 'center' },
                         { title: '名称(En)', field: 'CoNameEn', width: 280, align: 'center' },
                         { title: '排序', field: 'CoSort', width: 100, align: 'center' },
                         {
                             field: 'CoNormalImage', title: '图片', width: 80, align: 'center',
                             formatter: function (value, rowData) {
                                 return '<a class="fancybox_image" href="../upload/honor/' + rowData.CoNormalImage + '"></a>';
                             }
                         },
                       {
                           title: '修改', field: 'OpEdit', width: 80, align: 'center', formatter: function (value, rec) {
                               return '<a href="javascript:void(0);" mce_href="#" onclick="edit(\'' + rec.id + '\')">修改</a> ';
                           }
                       },
                        {
                            title: '删除', field: 'OpDelete', width: 80, align: 'center', formatter: function (value, rec) {
                                return '<a href="javascript:void(0);" mce_href="#" onclick="del(\'' + rec.id + '\')">删除</a> ';

                            }
                        }
                ]],
                pagination: true,
                rownumbers: true,
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        add();
                    }
                }, {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要修改记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            edit(selectData.id);
                        }
                    }

                }, {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要删除记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            del(selectData.id);
                        }

                    }

                }, {
                    text: '查找',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#search_honor').dialog("open");
                    }

                }]
            });
            $('#add_honor').dialog({
                title: '添加企业荣誉',
                
                width: 600,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addSave(function () { });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#add_honor').dialog('close');
                    }
                }]

            });
            $('#edit_honor').dialog({
                title: '修改企业荣誉',
                
                width: 600,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        editSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#edit_honor').dialog('close');
                    }
                }]
            });
            $('#search_honor').dialog({
                title: '检索企业荣誉',
                
                width: 400,
                height: 250,
                closed: true,
                buttons: [{
                    text: '查找',
                    iconCls: 'icon-ok',
                    handler: function () {
                        tableList.datagrid("reload", $('#search_honor_form').serializeObject());
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#search_honor').dialog('close');
                    }
                }]
            });
            $('#edit_honor_form').form({
                onBeforeLoad: function () {
                },
                onLoadSuccess: function () {
                    $('#edit_honor').dialog("open");
                },
                onLoadError: function () {
                }
            });
            $('#add_btn_upload').click(function () {
                $.ajaxFileUpload({
                    url: 'Handle/UploadHonorPicture.aspx',
                    fileElementId: 'add_upload',
                    dataType: 'json',
                    success: function (data) {
                        if (typeof (data.state) != 'undefined') {
                            if (data.state) {
                                $('#add_big_image').val(data.fileName);
                                $('#add_normal_image').val(data.fileName);
                                $('#add_small_image').val(data.thumFileName);
                                $('#add_upload_box').hide();
                                $('#add_delete_box').show();
                                $.messager.show({
                                    title: '提示',
                                    msg: data.message,
                                    timeout: 5000,
                                    showType: 'fade'
                                });
                            } else {
                                $.messager.show({
                                    title: '提示',
                                    msg: data.message,
                                    timeout: 5000,
                                    showType: 'fade'
                                });
                            }
                        }
                    },
                    error: function (data, status, e) {
                        $.messager.show({
                            title: '提示',
                            msg: e,
                            timeout: 5000,
                            showType: 'fade'
                        });
                    }
                });
            });
            $('#edit_btn_upload').click(function () {
                $.ajaxFileUpload({
                    url: 'Handle/UploadHonorPicture.aspx',
                    fileElementId: 'edit_upload',
                    dataType: 'json',
                    success: function (data) {
                        if (typeof (data.state) != 'undefined') {
                            if (data.state) {
                                $('#edit_big_image').val(data.fileName);
                                $('#edit_normal_image').val(data.fileName);
                                $('#edit_small_image').val(data.thumFileName);
                                $('#edit_upload_box').hide();
                                $('#edit_delete_box').show();
                                $.messager.show({
                                    title: '提示',
                                    msg: data.message,
                                    timeout: 5000,
                                    showType: 'fade'
                                });
                            } else {
                                $.messager.show({
                                    title: '提示',
                                    msg: data.message,
                                    timeout: 5000,
                                    showType: 'fade'
                                });
                            }
                        }
                    },
                    error: function (data, status, e) {
                        $.messager.show({
                            title: '提示',
                            msg: e,
                            timeout: 5000,
                            showType: 'fade'
                        });
                    }
                });
            });
            $('#btn_add_delete_image').click(function () {
                $.messager.confirm("提示", "确认删除?", function (b) {
                    if (b) {
                        $.ajax({
                            type: "POST",
                            url: "Handle/RemoveHonorPicture.aspx",
                            data: $('#add_honor_form').serialize(),
                            success: function (msg) {
                                $.messager.show({
                                    title: '提示',
                                    msg: msg.message,
                                    timeout: 5000,
                                    showType: 'fade'
                                });
                                if (msg.state) {
                                    $('#add_big_image').val('');
                                    $('#add_normal_image').val('');
                                    $('#add_small_image').val('');
                                    $('#add_upload_box').show('');
                                    $('#add_delete_box').hide('');
                                }
                            },
                            error: function () {
                                $.messager.show({
                                    title: '提示',
                                    msg: '删除失败！',
                                    timeout: 5000,
                                    showType: 'fade'
                                });
                            }
                        });
                    }
                });
            });
            $('#btn_edit_delete_image').click(function () {
                $.messager.confirm("提示", "确认删除?", function (b) {
                    if (b) {
                        $.ajax({
                            type: "POST",
                            url: "Handle/RemoveHonorPicture.aspx",
                            data: $('#edit_honor_form').serialize(),
                            success: function (msg) {
                                $.messager.show({
                                    title: '提示',
                                    msg: msg.message,
                                    timeout: 5000,
                                    showType: 'fade'
                                });
                                if (msg.state) {
                                    $('#edit_big_image').val('');
                                    $('#edit_normal_image').val('');
                                    $('#edit_small_image').val('');
                                    $('#edit_upload_box').show('');
                                    $('#edit_delete_box').hide('');
                                }
                            },
                            error: function () {
                                $.messager.show({
                                    title: '提示',
                                    msg: '删除失败！',
                                    timeout: 5000,
                                    showType: 'fade'
                                });
                            }
                        });
                    }
                });
            });
        });
        //获取企业荣誉详细
        function edit(id) {
            $('#edit_honor_form').form('load', 'Handle/GetHonorPictureDetailJson.aspx?id=' + id);
        }
        function del(id) {
            $.messager.confirm("提示", "确认删除?", function (b) {
                if (b) {
                    $.ajax({
                        type: "POST",
                        url: "Handle/DeleteHonor.aspx",
                        data: { id: id },
                        success: function (msg) {
                            $.messager.show({
                                title: '提示',
                                msg: msg.message,
                                timeout: 5000,
                                showType: 'fade'
                            });
                            if (msg.state)
                                $("#table_list").datagrid("reload");
                        },
                        error: function () {
                            $.messager.show({
                                title: '提示',
                                msg: '删除失败！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        }
                    });
                }
            });
        }
        function add() {
            $('#add_honor').dialog("open");
        }
        //添加保存
        function addSave() {
            $.ajax({
                type: "POST",
                url: "Handle/AddHonor.aspx",
                data: $('#add_honor_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $('#add_upload_box').show('');
                        $('#add_delete_box').hide('');
                        $('#add_honor_form')[0].reset();
                        $("#table_list").datagrid("reload");
                    }
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        //编辑保存
        function editSave() {
            $.ajax({
                type: "POST",
                url: "Handle/EditHonor.aspx",
                data: $('#edit_honor_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $("#table_list").datagrid("reload");
                    }
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
    </script>
</asp:Content>
